﻿using System.Data;
using System;
using System.Collections.Generic;

namespace Home.Haushalt.Lib.Element
{
    /// <summary>
    /// 
    /// </summary>
    [ElementExtension("Element", 3)]
    public class Member : ElementBase
    {
        #region CONSTANTS
        public new static readonly Type ElementType = typeof(Member);

        /// <summary></summary>
        public class Fields
        {
            public const string Id = ELEMENTPROPERTY_ID;
            public const string Label = ELEMENTPROPERTY_LABEL;
            public const string Description = ELEMENTPROPERTY_NOTE;
            public const string OpponentId = "o";
            public const string PostenId = "z";
            public const string DocumentId = "c";
            public const string Name = "n";
            public const string UserName = "u";
            public const string Pass = "p";
            public const string Link = "l";
            public const string Art = "a";
            public const string AutoLogin = "s";
        }
        #endregion CONSTANTS

        /// <summary></summary>
        public override string PropertyFormCaption { get { return (Row != null) ? Row[Fields.Name].ToString() : ""; } }

        /// <summary>
        /// 
        /// </summary>
        public Member() : base() { }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentDataRow"></param>
        public Member(DataRow parentDataRow) : base(parentDataRow) { }

        #region OVERRIDES

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override List<string> InputValidate()
        {
            List<string> result = new List<string>();

            if (BindingRow[Fields.Name].ToString().Trim().Length == 0) result.Add(GetInputValidateMessage(this.GetType(), Fields.Name, "missing"));

            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ElementBase New()
        {
            base.New();

            if (ParentElement is Posten)
            {
                Row[Fields.PostenId] = ParentElement.Row[Posten.Fields.Id];
                Row[Fields.OpponentId] = ParentElement.Row[Posten.Fields.OpponentId];
            }
            else if (ParentElement is Opponent)
            {
                Row[Fields.OpponentId] = ParentElement.Row[Opponent.Fields.Id];
            }

            return this;
        }

        #endregion OVERRIDES
    }
}
